import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_web_study/page/commodity_evaluation_page.dart';

import 'commodity_management_page.dart';

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  var leftList = [
    {"name": "商品管理", "isStick": true},
    {"name": "商品评价", "isStick": false},
  ];

  var tag = 0;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Row(
        children: [
          Container(
            width: 200,
            child: Column(
              children: [
                Container(
                  height: 100,
                  alignment: Alignment.center,
                  child: Text(
                    "甜甜圈",
                    style: TextStyle(
                        fontSize: 20,
                        fontWeight: FontWeight.bold,
                        color: Colors.red),
                  ),
                ),
                Expanded(
                    child: ListView.builder(
                        itemCount: leftList.length,
                        itemBuilder: (context, index) {
                          return GestureDetector(
                            child: Container(
                              decoration: BoxDecoration(
                                //设置边框
                                border: new Border.all(
                                    color: Colors.amberAccent, width: 0.5),
                                color: (leftList[index]["isStick"] as bool)
                                    ? Colors.black26
                                    : Colors.white,
                              ),
                              height: 50,
                              alignment: Alignment.center,
                              child: Text("${leftList[index]["name"]}"),
                            ),
                            onTap: () {
                              leftList.forEach((element) {
                                element["isStick"] = false;
                              });
                              leftList[index]["isStick"] = true;
                              tag = index;
                              setState(() {});
                            },
                          );
                        }))
              ],
            ),
          ),
          Expanded(
            child: tag == 0
                ? CommodityManagementPage()
                : CommodityEvaluationPage(),
          )
        ],
      ),
    );
  }
}
